package com.zlp.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;


/**  
 * 
 * @Title:  FanoutConfig.java   
 * @Package com.zlp.config   
 * @Description:    基本配置 信息
 * @author: 邹利平
 * @date:   2019年3月13日 下午2:02:35   
 * @version V1.0  
 */ 
@Component
public class FanoutConfig {

	// EMAIL 队列名称
	private String FANOUT_EMAIL_QUEUE = "fanout_email_queue";
	// SMS 队列名称
	private String FANOUT_SMS_QUEUE = "fanout_sms_queue";
	// EXCHANGE 交换机
	private String EXCHANGE_NAME = "fanoutExchange";
     
	// 注入spring容器中
	//定义 EMAIL
	@Bean
	public Queue fanOutEamilQueue() {
		return new Queue(FANOUT_EMAIL_QUEUE);
	}

	// 定义 SMS
	@Bean
	public Queue fanOutSmsQueue() {
		return new Queue(FANOUT_SMS_QUEUE);
	}

	// 定义 交换机
	@Bean
	FanoutExchange fanoutExchange() {
		return new FanoutExchange(EXCHANGE_NAME);
	}

	// 交换机绑定 EMAIL 队列
	@Bean
	Binding bindingExchangeEamil(Queue fanOutEamilQueue, FanoutExchange fanoutExchange) {
		return BindingBuilder.bind(fanOutEamilQueue).to(fanoutExchange);
	}

	// 交换机绑定 Sms 队列
	@Bean
	Binding bindingExchangeSms(Queue fanOutSmsQueue, FanoutExchange fanoutExchange) {
		return BindingBuilder.bind(fanOutSmsQueue).to(fanoutExchange);
	}
}
